package com.demo2do.fms.admin.dao.business;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Execute;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.demo2do.fms.entity.business.Finance;
import com.demo2do.fms.entity.business.balance.SapRevenueDetail;

/**
 * 
 * @author Ysy
 *
 */
@Dao("hibernate")
public interface FinanceDao {
    
    /**
     * list finance by financeIds
     * 
     * @param financeIds
     * @return
     */
    @Query("FROM Finance WHERE disabled = false AND id IN (:financeIds)")
    public List<Finance> listByFinanceIds(@Variable("financeIds") List<Long> financeIds);
    
    /**
     * list finance by shipment_finance_id
     * 
     * @param shipmentFinanceIds
     * @return
     */
    @Query("FROM Finance WHERE disabled = false AND shipmentFinanceId IN (:shipmentFinanceIds)")
    public List<Finance> listByShipmentFinance(@Variable("shipmentFinanceIds") List<Long> shipmentFinanceIds);
    
    /**
     * list finance by parent shipment_finance_id
     * 
     * @param shipmentFinanceId
     * @return
     */
    @Query("FROM Finance WHERE disabled = false AND parentId = :parentId")
    public List<Finance> listChildByShipmentFinance(@Variable("parentId") Long shipmentFinanceId);
    
    /**
     * load finance by shipment_finance_id
     * 
     * @param shipmentFinanceId
     * @return
     */
    @Query("From Finance f where f.disabled = false AND f.shipmentFinanceId = :shipmentFinanceId")
    public Finance load(@Variable("shipmentFinanceId") Long shipmentFinanceId);
    
    /**
     * @param shipmentId
     * @param companyId
     * @return
     */
    @Query("FROM Finance WHERE disabled = false AND shipmentId = :shipmentId AND companyId = :companyId")
    public Finance load(@Variable("shipmentId") Long shipmentId, @Variable("companyId") Long companyId);
    
    /**
     * @param shipmentId
     * @param loadNumber
     * @param companyId
     * @return
     */
    @Query("FROM Finance WHERE disabled = false AND shipmentId = :shipmentId AND loadNumber = :loadNumber AND companyId = :companyId")
    public Finance load(@Variable("shipmentId") Long shipmentId, @Variable("loadNumber") String loadNumber, @Variable("companyId") Long companyId);
    
    /**
     * update collectStatus by shipmentFinanceId
     * 
     * @param shipmentFinanceIds
     * @param collectStatus
     * @param sessionId
     */
    @Execute("UPDATE Finance SET collectStatus = :collectStatus, sessionId = :sessionId WHERE disabled = false AND shipmentFinanceId IN (:shipmentFinanceIds)")
    public void updateCollectStatus(@Variable("shipmentFinanceIds") List<Long> shipmentFinanceIds, @Variable("collectStatus") String collectStatus, @Variable("sessionId") String sessionId);
    
    /**
     * get revenue_detail by finance_id
     * 
     * @param financeId
     * @return
     */
    @Query("FROM SapRevenueDetail WHERE disabled = false AND financeId = :financeId")
    public SapRevenueDetail getRevenueByFinanceId(@Variable("financeId") Long financeId);
    
}
